package com.suixinsanren.design.iterator.demo02;

import java.util.ArrayList;

public class PancakeHoseMenuIterator implements Iterator<MenuItem> {

    private ArrayList<MenuItem> menuItems;
    private int location = 0;

    public PancakeHoseMenuIterator(ArrayList<MenuItem> menuItems) {
        this.menuItems = menuItems;
    }

    @Override
    public boolean hasNext() {
        return location < menuItems.size();
    }

    @Override
    public MenuItem next() {
        return menuItems.get(location++);
    }

    @Override
    public void remove() {
        menuItems.remove(menuItems.get(--location));
    }

}
